﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void PageLoad()
        {
            DataTable dt = new DataTable();
            
            PhongBanBUS phongban_bus = new PhongBanBUS();            
            dt = phongban_bus.sp_PhongBan();            
            cbPhongBan.ValueMember="MaPhongBan";
            cbPhongBan.DisplayMember="TenPhongBan";
            cbPhongBan.DataSource = dt;

            ViTriBUS vitri_bus = new ViTriBUS();
            dt = vitri_bus.sp_ViTri();            
            cbViTri.ValueMember = "MaViTri";
            cbViTri.DisplayMember = "TenViTri";
            cbViTri.DataSource = dt;

            TrangThaiBUS trangthai_bus = new TrangThaiBUS();
            dt = trangthai_bus.sp_TrangThai();
            cbTrangThai.ValueMember = "MaTrangThai";
            cbTrangThai.DisplayMember = "TenTrangThai";
            cbTrangThai.DataSource = dt;

            LoadGrid();
           
        }
        public DataTable LoadGrid()
        {
            DataTable dt = new DataTable();
            NhanVienBUS nhanvien_bus = new NhanVienBUS();
            dt = nhanvien_bus.sp_DanhSachNhanVien();
            GridDSNV.DataSource = dt;
            return dt;
        }
        private void btnThemNV_Click(object sender, EventArgs e)
        {
            NhanVienDTO nhavien_dto = new NhanVienDTO();
            nhavien_dto.TenNhanVien = txtTen.Text;
            nhavien_dto.TaiKhoanNganHang = txttaikhoan.Text;
            nhavien_dto.Phai = txtphai.Text;
            nhavien_dto.PassWord = txtpass.Text;
            nhavien_dto.DiaChi = txtdiachi.Text;
            nhavien_dto.DienThoai = txtdienthoai.Text;
            nhavien_dto.Email = txtemail.Text;
            nhavien_dto.NgaySinh = cbngay.Value;
            nhavien_dto.MaVitri = int.Parse(cbViTri.SelectedValue.ToString());
            nhavien_dto.MaTrangThai = int.Parse(cbTrangThai.SelectedValue.ToString());
            nhavien_dto.MaPhongBan = int.Parse(cbPhongBan.SelectedValue.ToString());

            NhanVienBUS nhanvien_bus = new NhanVienBUS();
            nhanvien_bus.sp_ThemNhanVien(nhavien_dto);

            LoadGrid();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            PageLoad();
        }

    }
}